package com.xiaomei.manager.utils;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class STSAccess {
	private STSAccess() {}

	private static final String key = "9694358131015327";
	
	private static final Logger logger = Logger.getLogger(STSAccess.class);
	
	public static String REGION;
	public static String STS_API_VERSION;
	// RAM用户（子账号）
	public static String ACCESSKEYID;      
	// RAM用户（子账号）
	public static String ACCESSKEYSECRET;  
	// RAM角色
	public static String ROLEARN;      
	// 令牌有效时间
	public static Long TOKENEXPIRETIME;  
	// 授权策略
	public static String POLICY;  
	
	static {
		Properties prop = new Properties();
		try {
			InputStream is = HttpSender.class.getClassLoader().getResourceAsStream("oss-sts.properties");
			prop.load(is);
			String region = prop.getProperty("region");
			if (region != null) {
				REGION =  DESUtils.Decrypt(region, DESUtils.hex2byte(key));
			}
			
			String sts_api_version = prop.getProperty("sts_api_version");
			if (sts_api_version != null) {
				STS_API_VERSION =  DESUtils.Decrypt(sts_api_version, DESUtils.hex2byte(key));
			}
			
			String AccessKeyID = prop.getProperty("AccessKeyID");
			if (AccessKeyID != null) {
				ACCESSKEYID =  DESUtils.Decrypt(AccessKeyID, DESUtils.hex2byte(key));
			}
			
			String AccessKeySecret = prop.getProperty("AccessKeySecret");
			if (AccessKeySecret != null) {
				ACCESSKEYSECRET =  DESUtils.Decrypt(AccessKeySecret, DESUtils.hex2byte(key));
			}
			
			String RoleArn = prop.getProperty("RoleArn");
			if (RoleArn != null) {
				ROLEARN =  DESUtils.Decrypt(RoleArn, DESUtils.hex2byte(key));
			}
			
			String TokenExpireTime = prop.getProperty("TokenExpireTime");
			if (TokenExpireTime != null) {
				TOKENEXPIRETIME =  Long.valueOf(DESUtils.Decrypt(TokenExpireTime, DESUtils.hex2byte(key)));
			}
			
			String Policy = prop.getProperty("Policy");
			if (Policy != null) {
				POLICY =  DESUtils.Decrypt(Policy, DESUtils.hex2byte(key));
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("加载短信平台配置失败");
		} 
	}
}
